package com.fun.wyunfei.timeline.util;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.widget.EditText;

import java.util.Calendar;
import java.util.Date;

@SuppressWarnings("unused")
public class DatePickerUtil {


    public static void showDatePicker(Context context, EditText editText) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        new DatePickerDialog(context, 0, (view, year, month, dayOfMonth) -> {
            String time = DateUtil.parseDf1Date(year, month, dayOfMonth);
            editText.setText(time);
        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.DATE)).show();
    }

    public static void showDatePicker(Context context, EditText editText, Calendar calendar) {
        new DatePickerDialog(context, 0, (view, year, month, dayOfMonth) -> {
            String time = DateUtil.parseDf1Date(year, month, dayOfMonth);
            editText.setText(time);
        }, calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.DATE)).show();
    }

    public static void showDatePicker(Context context, EditText editText, Calendar calendar, DatePickerDialog.OnDateSetListener listener) {
        new DatePickerDialog(context, 0, listener,
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.DATE)).show();

    }

    public static void showTimePicker(Context context, EditText editText, int hour, int minute, boolean is24) {
        new TimePickerDialog(context, 0, ((view, hourOfDay, minute1) -> {
            String time = hour + ":" + minute;
            editText.setText(time);
        }), hour, minute, is24).show();
    }

    public static void showTimePicker(Context context, TimePickerDialog.OnTimeSetListener linstener, int hour, int minute, boolean is24) {
        new TimePickerDialog(context, 0, linstener, hour, minute, is24).show();
    }

    public static Calendar getCalendar(int year, int mouth, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);          // 设置当前年
        calendar.set(Calendar.MONTH, mouth - 1);    // 设置月份
        calendar.set(Calendar.DATE, day);           // 设置日
        return calendar;
    }

}
